package com.hutao.manage.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hutao.manage.service.BasicInfoService;
import com.hutao.manage.util.JsonUtils;

@Controller
@RequestMapping("/baseinfo")
public class BasicInfoController {

	@Autowired
	private BasicInfoService basicInfoService;
	
	@RequestMapping(value="/queryDisease",method=RequestMethod.POST)
	@ResponseBody
	public String queryDisease(String queryValueType,String queryValue,Model model){
		List<Map<String,Object>> diseases = new ArrayList<Map<String,Object>>();
		if(queryValueType.equals("3")){
			diseases = basicInfoService.queryDiseaseByLikeCode(queryValue);
		}else if(queryValueType.equals("1")){
			diseases = basicInfoService.queryDiseaseByLikeIndexCode(queryValue);
		}else{
			diseases = basicInfoService.queryDiseaseByLikeName(queryValue);
		}
		
		String resultJson = JsonUtils.objectToJson(diseases);
		return resultJson;
	}
	
	@RequestMapping(value="/queryOperation",method=RequestMethod.POST)
	@ResponseBody
	public String queryOperation(String queryValueType,String queryValue,Model model){
		List<Map<String,Object>> operations = new ArrayList<Map<String,Object>>();
		if("3".equals(queryValueType)){
			operations = basicInfoService.queryOperationByLikeCode(queryValue);
		}else if("1".equals(queryValueType)){
			operations = basicInfoService.queryOperationByLikeIndexCode(queryValue);
		}else{
			operations = basicInfoService.queryOperationByLikeName(queryValue);
		}
		
		String resultJson = JsonUtils.objectToJson(operations);
		return resultJson;
	}
	
	
	@RequestMapping(value="/queryDoctor",method=RequestMethod.POST)
	@ResponseBody
	public String queryDoctor(String queryValueType,String queryValue,Model model){
		List<Map<String,Object>> doctors = new ArrayList<Map<String,Object>>();
		if(queryValueType.equals("3")){
			doctors = basicInfoService.queryDoctorByLikeName(queryValue);
		}else if(queryValueType.equals("1")){
			doctors = basicInfoService.queryDoctorByLikeName(queryValue);
		}else{
			doctors = basicInfoService.queryDoctorByLikeName(queryValue);
		}
		
		String resultJson = JsonUtils.objectToJson(doctors);
		return resultJson;
	}
	
	
	@RequestMapping(value="/queryDiagnosisSubject",method=RequestMethod.POST)
	@ResponseBody
	public String queryDiagnosisSubject(String queryValueType,String queryValue,Model model){
		List<Map<String,Object>> diagnosisSubjects = new ArrayList<Map<String,Object>>();
		if(queryValueType.equals("3")){
			diagnosisSubjects = basicInfoService.queryDiagnosisSubjectByLikeName(queryValue);
		}else if(queryValueType.equals("1")){
			diagnosisSubjects = basicInfoService.queryDiagnosisSubjectByLikeName(queryValue);
		}else{
			diagnosisSubjects = basicInfoService.queryDiagnosisSubjectByLikeName(queryValue);
		}
		
		String resultJson = JsonUtils.objectToJson(diagnosisSubjects);
		return resultJson;
	}
	
	@GetMapping("/ajax_medical_offices")
	@ResponseBody
	public Map<String, Object> ajaxMedicalOffices(HttpServletResponse response,Integer hospitalId) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		Map<String, Object> map = new HashMap<>();
		List<Map<String, Object>> medicalOfficesList = basicInfoService.getMedicalOfficesByHospitalId(hospitalId);
		map.put("medicalOfficesList", medicalOfficesList);
		return map;
	}
	
	
	
	
	
	
}
